package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.apis.admin.AdChannelController;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author feihao
 * @version 1.0
 * @date 2021/7/21 20:04
 */

@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController implements AdChannelController {

    @Autowired
    private AdChannelService adChannelService;

    /**
     * 根据名称分页查询频道信息
     *
     * @param channelDto
     * @return
     */
    @Override
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        return adChannelService.findByNameAndPage(channelDto);
    }


    /**
     * 保存channel:
     *
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("save")
    public ResponseResult saveChannel(@RequestBody AdChannel adChannel) {

        return adChannelService.insert(adChannel);
    }

    /**
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("update")
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel) {
        return adChannelService.updateChannel(adChannel);
    }

    @Override
    @GetMapping("del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }
}
